package cn.com.pureAppApi.serviceImpl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;
import java.util.List;
import java.util.ArrayList;

import cn.com.pureAppApi.utils.PageUtils;
import cn.com.pureAppApi.utils.Query;

import cn.com.pureAppApi.entity.AuthoritiesEntity;
import cn.com.pureAppApi.service.IAuthoritiesService;
import cn.com.pureAppApi.dao.AuthoritiesMapper;
import cn.com.pureAppApi.entity.vo.AuthoritiesEntityVo;


import com.github.pagehelper.PageHelper;
import cn.com.pureAppApi.utils.ResponseResult;


/**
 * 接口实现ServiceImpl
 * InnoDB free: 10240 kB
 *
 * QQ讨论群:76989293
 * @email 2696701142@qq.com
 * @date 2018-06-12 16:51:48
 */
@Service
public class AuthoritiesServiceImpl   implements IAuthoritiesService {

	@Autowired
	private AuthoritiesMapper themapper;
	
	@Override
	public List<AuthoritiesEntityVo> findListPageVo(Integer page, Integer rows) {	
		AuthoritiesEntity record= new AuthoritiesEntity();
		PageHelper.startPage(page, rows, false);
		List<AuthoritiesEntity> list = themapper.select(record);		
		List<AuthoritiesEntityVo> listVo = new ArrayList<AuthoritiesEntityVo>();
		if(list!=null && list.size()>0){
			for (AuthoritiesEntity entity : list) {
			AuthoritiesEntityVo vo  =new AuthoritiesEntityVo();
					vo.setId(entity.getId());//  
					vo.setUsername(entity.getUsername());//  
					vo.setAuthority(entity.getAuthority());//  
					listVo.add(vo);
			}
		}
		return listVo;
		//分页查询		

	}
	
	@Override
	public List<AuthoritiesEntityVo> findListPageVoByParamId(Integer page, Integer rows,Long oneByParamId) {	
		AuthoritiesEntity record= new AuthoritiesEntity();
		//record.setId(oneByParamId);
		PageHelper.startPage(page, rows, false);
		List<AuthoritiesEntity> list = themapper.select(record);		
		List<AuthoritiesEntityVo> listVo = new ArrayList<AuthoritiesEntityVo>();
		if(list!=null && list.size()>0){
			for (AuthoritiesEntity entity : list) {
				AuthoritiesEntityVo vo  =new AuthoritiesEntityVo();
							vo.setId(entity.getId());//  
							vo.setUsername(entity.getUsername());//  
							vo.setAuthority(entity.getAuthority());//  
							listVo.add(vo);
			}
		}
		return listVo;
	}
	
	@Override
	public AuthoritiesEntityVo findSelectOneVoByParamId(Long oneByParamId) {	
			AuthoritiesEntity record= new AuthoritiesEntity();
			//record.setId(oneByParamId);		
			AuthoritiesEntity entity = themapper.selectOne(record);		
			AuthoritiesEntityVo vo  =new AuthoritiesEntityVo();
			if(entity!=null ){
					vo.setId(entity.getId());//  
					vo.setUsername(entity.getUsername());//  
					vo.setAuthority(entity.getAuthority());//  
						}
			return vo;
	}
	
	@Override
   	public AuthoritiesEntityVo insertReturnVo(AuthoritiesEntityVo vo){
   		if (null==vo) {
			ResponseResult.error();
		}
		AuthoritiesEntity record= new AuthoritiesEntity();
		if(vo!=null){
		record.setId(vo.getId());//  
		record.setUsername(vo.getUsername());//  
		record.setAuthority(vo.getAuthority());//  
			}
		themapper.insertSelective(record);
		return vo;
   	}
   	
   	@Override
   	public AuthoritiesEntityVo editReturnVo(AuthoritiesEntityVo vo){
   		if (null==vo) {
			ResponseResult.error();
		}
		AuthoritiesEntity record= new AuthoritiesEntity();
		if(vo!=null){
			record.setId(vo.getId());//  
			record.setUsername(vo.getUsername());//  
			record.setAuthority(vo.getAuthority());//  
				}
		themapper.updateByPrimaryKeySelective(record);
		return vo;
   	}
   	
	@Override
	public List<AuthoritiesEntity> findListPage(Integer page, Integer rows) {
		//分页查询		
		AuthoritiesEntity record= new AuthoritiesEntity();
		PageHelper.startPage(page, rows, false);
		List<AuthoritiesEntity> list = themapper.selectAll();		
		return list;
	}
	
	@Override
	public List<AuthoritiesEntity>findListByParamId(Integer page, Integer rows,Long oneByParamId){
		//分页查询		
		AuthoritiesEntity record= new AuthoritiesEntity();
		//record.setId(oneByParamId)
		PageHelper.startPage(page, rows, false);
		List<AuthoritiesEntity> list = themapper.select(record);		
		return list;
	}
 
   	 
   	@Override
   	public AuthoritiesEntity insert(AuthoritiesEntity vo){
   		if (null==vo) {
			ResponseResult.error();
		}
		AuthoritiesEntity record= new AuthoritiesEntity();
		if(vo!=null){
		record.setId(vo.getId());//  
		record.setUsername(vo.getUsername());//  
		record.setAuthority(vo.getAuthority());//  
			}
		themapper.insertSelective(record);
		return vo;
   	}
   	
   	@Override
   	public AuthoritiesEntity edit(AuthoritiesEntity vo){
   		if (null==vo) {
			ResponseResult.error();
		}
		AuthoritiesEntity record= new AuthoritiesEntity();
		if(vo!=null){
		record.setId(vo.getId());//  
		record.setUsername(vo.getUsername());//  
		record.setAuthority(vo.getAuthority());//  
			}
		themapper.updateByPrimaryKeySelective(record);
		return vo;
   	}
   	
   	@Override
	public int save(AuthoritiesEntity vo){
		if (null==vo) {
			ResponseResult.error();
		}
		AuthoritiesEntity record= new AuthoritiesEntity();
		if(vo!=null){
		record.setId(vo.getId());//  
		record.setUsername(vo.getUsername());//  
		record.setAuthority(vo.getAuthority());//  
			}
		return themapper.insertSelective(record);
	}
	
	@Override
	public int update(AuthoritiesEntity vo){
		if (null==vo) {
			ResponseResult.error();
		}
		AuthoritiesEntity record= new AuthoritiesEntity();
		if(vo!=null){
		record.setId(vo.getId());//  
		record.setUsername(vo.getUsername());//  
		record.setAuthority(vo.getAuthority());//  
			}
		return themapper.updateByPrimaryKeySelective(record);
	}
	
	@Override
	public int remove(Integer id){
		return themapper.deleteByPrimaryKey(id);
	}
}
